//
//  PainterLineIndex.m
//  ChartRefactor
//
//  Created by CaoJun on 15/3/16.
//  Copyright (c) 2015年 CaoJun. All rights reserved.
//

#import "PainterLineIndex.h"

using namespace std;
using namespace ytx;

@implementation PainterLineIndex

- (void)drawLine:(CGRect)cgrect withContext:(ChartCanvas *) ctx withViewModelIndexPosition:(ViewModelIndexPosition *) indexPosition  withLineData:(vector<double>) lineData withColor:(NSString *)color
{
    YTXConfig * config = YTXConfig::getInstance();
    ytx::Style style = config->style;
    Rectangle & rect = indexPosition->getRectangle();

    int startIndex = indexPosition->getStartDataIndex(), endIndex = indexPosition->getEndDataIndex();
    float  zoomX = rect.getZoomX(), tempX = rect.getBeginX() + zoomX * 0.5, tempY = 0;

    NSMutableArray * points = [NSMutableArray new];
    int i = 0;
    for(i = startIndex; i < endIndex; i++){
        if (!isnan(lineData[i])) {
            tempY = rect.getPxY(lineData[i]);
            [points addObject: [NSValue valueWithCGPoint:CGPointMake(tempX, tempY)]];
//            points.push_back(ccp(tempX,tempY));
        }
        tempX += zoomX;
    }
    
    if(points.count <= 1 ){
        return;
    }

//    ctx.setLineWidth(style.quoteLineWidth).setStrokeStyle(color).drawLines(points);
    [ctx setLineWidth:style.quoteLineWidth];
    [ctx setStrokeStyle:color];
    [ctx drawLines: [NSArray arrayWithArray:points] ];
}

@end
